<!DOCTYPE html>
<html>
<head>
	<title>点单系统</title>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="../../css/bootstrap.min.css" rel="stylesheet">
	<!-- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> -->
	<link rel="stylesheet" type="text/css" href="../../css/order.css">
	<link rel="stylesheet" type="text/css" href="../../css/waiter.css">
</head>
<body>
	<div id="head">
		<div class="navbar navbar-default  navbar-inverse" role="navigation">
			<a href="./waiter.html">
				<div class="head-left">
					<span class="glyphicon glyphicon-user"></span>
				</div>
			</a>
			<div class="head-center">
				饭店
			</div>
			<button type="button" class="btn btn-danger" id="menu">
				<span style="margin-right: 5px" class="glyphicon glyphicon-th-list"></span>已点
			</button>
		</div>
	</div>

	<div id="right" style="left: 0">
		<div class="right-head">
			<ol class="breadcrumb">
				<li><a href="./order.html">菜单</a></li>
				<li class="active" id="bav">已点</li>
			</ol> 
		</div>
		<div class="con">
			<div class="container">
				<div class="row">
					<div class="col-md-12">
						<div class="panel panel-default">
							<div class="panel-body">

								<div class="row" style="margin-top: 20px">
									<label class="col-lg-2 col-lg-offset-5 control-label" style="text-align: center;" id="desk">
									</label>
								</div>
								<div class="row">
									<div class="col-lg-8 col-lg-offset-2">
										<div class="table-responsive">
											<table class="table table-striped table-bordered table-hover">
												<thead>
													<tr>
														<th>菜名</th>
														<th>份数</th>
														<th>状态</th>
														<th>移除</th>
													</tr>
												</thead>
												<tbody id="foods">
												</tbody>
									</table>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-2 col-lg-offset-5">
						<button class="btn btn-primary" type="button" id="al-add">提 交</button> 
						<button class="btn btn-danger" type="button" id="al-delete">返回</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</div>
</div>
</div>
</div>

<!-- <script type="text/javascript" src="../../js/order.js"></script> -->
<script src="../../js/Jquary/jquery-3.2.1.min.js"></script>
<script src="../../js/Jquary/jquery.easyui.min.js"></script>
<script src="../../js/bootstrap.min.js"></script> 
<script type="text/javascript">
	$(document).ready(function(){
		$("#menu-AA").click(function(){
			window.location.assign("order.html");
			$("#menu-B").removeClass("act");
			$("#menu-C").removeClass("act");
			$("#menu-A").removeClass("act");
			$("#menu-A").addClass("act");
			$("#bav").text("锅类")
		})
	
		$("#menu-BB").click(function(){
			window.location.assign("order.html");
			$("#menu-B").removeClass("act");
			$("#menu-C").removeClass("act");
			$("#menu-A").removeClass("act");
			$("#menu-B").addClass("act");
			$("#bav").text("主食类")
		})
		$("#menu-CC").click(function(){
			window.location.assign("order.html");
			$("#menu-B").removeClass("act");
			$("#menu-C").removeClass("act");
			$("#menu-A").removeClass("act");
			$("#menu-C").addClass("act");
			$("#bav").text("酒水类")
		})
		var positionid = sessionStorage.positionid;
		if(positionid!=-1){//查看该张桌点了什么菜
			seeOrder(positionid);
		}else{
			alert("请到上一级页面选择位置");
		}
		var positionname = sessionStorage.positionname;
		$("#desk").empty();
		$("#desk").append(positionname);
		
		$("#foods").on('click', '.reduce',function(){
				var orderid = $(this).attr("name");
				var num = prompt("输入退回数量:","1");
				if(parseInt(num)==num&&num!=null){
					reduceFood(orderid,num);
				}
				seeOrder(positionid);
		});
		$("#al-delete").click(function(){
			window.location.assign("./order.html");
		})
		$("#al-add").click(function(){
			$.ajax({
					type:"get",
					url:"/ldss/orders/submitorder",
					async:false,
					data:{
							positionid:positionid
						},
					dataType:"json",
					success: function (data) {
						if(data.success){
							alert(data.message);
							window.location.assign("./order.html");
						}
					}
			});
		})
	})
	function seeOrder(positionid){
		$.ajax({
			type:"get",
			url:"/ldss/orders/showmenu",
			async:false,
			data:{
					positionid:positionid
				},
			dataType:"json",
			success: function (data) {
				if(data.success){
					var data = data.data;
					$("#foods").empty();
					for(var i = 0; i < data.length; i++){
						$("#foods").append(
							"<tr>"+
								"<td>"+data[i].menuname+"</td>"+
								"<td>"+data[i].num+"</td>"+
								"<td>"+data[i].ordertype+"</td>"+
								"<td>"+ 
									"<button type='button' class='btn btn-primary reduce' name='"+data[i].id+"'>退回</button>"+
								"</td>"+
							"</tr>"
						);
					}
				}
			}
			/* success: function (data) {
				if(data.success){
					var data = data.data;
					$("#foods").empty();
					var allprise = 0;
					for(var i = 0; i < data.length; i++){
						var everpeist = data[i].num*data[i].menuprise;
						allprise = allprise+everpeist;
						$("#foods").append(
							"<tr>"+
								"<td>"+data[i].menuname+"</td>"+
								"<td>"+data[i].menuprise+"</td>"+
								"<td>"+data[i].num+"</td>"+
								"<td>"+everpeist+"</td>"+
								"<td>"+data[i].ordertype+"</td>"+
								"<td>"+ 
									"<button type='button' class='btn btn-primary reduce' name='"+data[i].id+"'>取消</button>"+
								"</td>"+
							"</tr>"
						);
					}
					$("#foods").append(
						"<tr>"+
							"<td colspan='3'>总价</td>"+
							"<td colspan='3'>"+allprise+"</td>"+
						"</tr>"
					);
				}else{
					alert(data.message);
				}
			} */
		});
	}
	function reduceFood(orderid,num){
		$.ajax({
			type:"get",
			url:"/ldss/orders/reduce",
			async:false,
			data:{
					orderid:orderid,
					num:num
				},
			dataType:"json",
			success: function (data) {
				if(data.success){
					var data = data;
					alert(data.message);
				}else{
					alert(data.message);
				}
			}
		});
	}
</script>
</body>
</html>